package com.baizhi.cmfz.util;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPollUtil {

    /*
       1.   static Runtime getRuntime()   返回与当前Java应用程序关联的运行时对象。
       2.   int availableProcessors()     返回可用于Java虚拟机的处理器数量。

     */

    private static int corePoolSize = Runtime.getRuntime().availableProcessors();

    /**
     * corePoolSize用于指定核心线程数量
     * maximumPoolSize指定最大线程数
     * keepAliveTime和TimeUnit指定线程空闲后的最大存活时间
     */
    public static ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, corePoolSize + 1, 10l, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(1000));


    public static int getCorePoolSize() {
        return corePoolSize;
    }
}
